//package com.zby.charity.config;
//
//import cn.hutool.core.lang.Assert;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.BeansException;
//import org.springframework.beans.FatalBeanException;
//import org.springframework.lang.Nullable;
//
//import java.beans.PropertyDescriptor;
//import java.lang.reflect.Method;
//import java.util.Arrays;
//import java.util.Collections;
//import java.util.List;
//
//
//import static org.springframework.util.Assert;
//import static org.springframework.util.ReflectionUtils.invokeMethod;
//
//public class MyBeanUtils extends BeanUtils {
//
//    private static void copyProperties(Object source, Object target, @Nullable Class<?> editable, @Nullable String... ignoreProperties) throws BeansException {
//        Assert.notNull(source, "Source must not be null");
//        Assert.notNull(target, "Target must not be null");
//
//        Class<?> actualEditable = (editable != null && editable.isInstance(target)) ? editable : target.getClass();
//
//        PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
//        List<String> ignoreList = (ignoreProperties != null) ? Arrays.asList(ignoreProperties) : Collections.emptyList();
//
//        for (PropertyDescriptor targetPd : targetPds) {
//            Method writeMethod = targetPd.getWriteMethod();
//            if (writeMethod != null && !ignoreList.contains(targetPd.getName())) {
//                PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
//                if (sourcePd != null) {
//                    Method readMethod = sourcePd.getReadMethod();
//                    if (readMethod != null && isAssignable(readMethod, writeMethod)) {
//                        try {
//                            Object value = invokeMethod(readMethod, source);
//                            // 只有当源对象的属性值不为 null 时才进行复制
//                            if (value != null) {
//                                invokeMethod(writeMethod, target, value);
//                            }
//                        } catch (Throwable ex) {
//                            throw new FatalBeanException("Could not copy property '" + targetPd.getName() + "' from source [" + source.getClass().getName() + "] to target [" + target.getClass().getName() + "]", ex);
//                        }
//                    }
//                }
//            }
//        }
//    }
//
//}
